package com.common;
import java.util.Date;

/**
 * Created by lzb on 2017/8/10.
 */
public class BussResp<T> {

    //编码约定
    public static int ERROR=999;
    public static int SUCCESS=0;
    public static int UNLOGIN=-1;
    public static int NOPERMISSION=-2;

    public boolean success=true;//是否成功
    public T data;//返回的业务数据
    public String message;//返回的信息
    public Integer code=0;//返回的代码


    public String tccid;
    public Date timeout;

    public BussResp(){}

    private BussResp(boolean success, T data, String message, Integer code){
        this.success=success;
        this.data=data;
        this.message=message;
        this.code=code;
    }


    public static BussResp createResp(boolean success,Object data,String message,Integer code){
        return new BussResp(success,data,message,code);
    }

    /**
     * 默认成功
     * @param data
     * @return
     */
    public static BussResp createResp(Object data){
        return new BussResp(true,data,null,SUCCESS);
    }

    public static BussResp createResp(Object data,String message){
        return new BussResp(true,data,message,SUCCESS);
    }


    public static BussResp createResp(boolean success,String message,Integer code){
        return new BussResp(success,null,message,code);
    }

    public static BussResp Success(String message){
        return createResp(null,message);
    }

    public static BussResp Fail(String message){
        return createResp(false,message,ERROR);
    }
}